package com.team20.map_demo.service;

import com.team20.map_demo.domain.Doorplate;
import com.team20.map_demo.domain.DoorplateExample;
import com.team20.map_demo.domain.Region;
import com.team20.map_demo.domain.Street;
import com.team20.map_demo.mapper.DoorplateMapper;
import com.team20.map_demo.mapper.RegionMapper;
import com.team20.map_demo.mapper.StreetMapper;
import io.micrometer.core.instrument.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DoorplateIServiceImpl implements DoorplateService {
    @Autowired
    private DoorplateMapper doorplateMapper;
    @Autowired
    private RegionMapper regionMapper;
    @Autowired
    private StreetMapper streetMapper;
    @Override
    public Doorplate findDoorplateByPrimaryKey(String id) {

        return doorplateMapper.selectByPrimaryKey(id);
    }

    @Override
    public int saveDoorplate(Doorplate doorplate) {
        if (StringUtils.isNotBlank(doorplate.getId())){
            return doorplateMapper.updateByPrimaryKey(doorplate);
        }else {
            return  doorplateMapper.insert(doorplate);
        }
    }

    @Override
    public int deleteDoorplateByPrimsryKey(String id) {
        return doorplateMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Doorplate> findAllDoorplate() {

        return doorplateMapper.selectByExample(new DoorplateExample());
    }


    @Override
    public List<Doorplate> getDoorplateByStreetId(String id) {
        return doorplateMapper.getDoorplateByStreetId(id);
    }

    @Override
    public List<Region> getAllRegion() {
        return regionMapper.selectAllRegion();
    }

    @Override
    public List<Doorplate> streetDoorplate(String streetName) {
        return  doorplateMapper.streetDoorplate(streetName);
    }

    @Override
    public List<Street> getStreetBytRId(String id) {
        return streetMapper.getStreetBytRId(id);
    }


}
